<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - src/caffe/layers/memory_data_layer.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../index.html">top level</a> - <a href="index.html">src/caffe/layers</a> - memory_data_layer.cpp<span style="font-size: 80%;"> (source / <a href="memory_data_layer.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">74</td>
            <td class="headerCovTableEntryLo">2.7 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">16</td>
            <td class="headerCovTableEntryLo">12.5 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #ifdef USE_OPENCV</a>
<span class="lineNum">       2 </span>            : #include &lt;opencv2/core/core.hpp&gt;
<span class="lineNum">       3 </span>            : #endif  // USE_OPENCV
<span class="lineNum">       4 </span>            : 
<span class="lineNum">       5 </span>            : #include &lt;vector&gt;
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #include &quot;caffe/layers/memory_data_layer.hpp&quot;
<span class="lineNum">       8 </span>            : 
<span class="lineNum">       9 </span>            : namespace caffe {
<a name="10"><span class="lineNum">      10 </span>            : </a>
<span class="lineNum">      11 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">      12 </span><span class="lineNoCov">          0 : void MemoryDataLayer&lt;Dtype&gt;::DataLayerSetUp(const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; bottom,</span>
<span class="lineNum">      13 </span>            :      const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; top) {
<span class="lineNum">      14 </span><span class="lineNoCov">          0 :   batch_size_ = this-&gt;layer_param_.memory_data_param().batch_size();</span>
<span class="lineNum">      15 </span><span class="lineNoCov">          0 :   channels_ = this-&gt;layer_param_.memory_data_param().channels();</span>
<span class="lineNum">      16 </span><span class="lineNoCov">          0 :   height_ = this-&gt;layer_param_.memory_data_param().height();</span>
<span class="lineNum">      17 </span><span class="lineNoCov">          0 :   width_ = this-&gt;layer_param_.memory_data_param().width();</span>
<span class="lineNum">      18 </span><span class="lineNoCov">          0 :   size_ = channels_ * height_ * width_;</span>
<span class="lineNum">      19 </span><span class="lineNoCov">          0 :   CHECK_GT(batch_size_ * size_, 0) &lt;&lt;</span>
<span class="lineNum">      20 </span>            :       &quot;batch_size, channels, height, and width must be specified and&quot;
<span class="lineNum">      21 </span>            :       &quot; positive in memory_data_param&quot;;
<span class="lineNum">      22 </span><span class="lineNoCov">          0 :   vector&lt;int&gt; label_shape(1, batch_size_);</span>
<span class="lineNum">      23 </span><span class="lineNoCov">          0 :   top[0]-&gt;Reshape(batch_size_, channels_, height_, width_);</span>
<span class="lineNum">      24 </span><span class="lineNoCov">          0 :   top[1]-&gt;Reshape(label_shape);</span>
<span class="lineNum">      25 </span><span class="lineNoCov">          0 :   added_data_.Reshape(batch_size_, channels_, height_, width_);</span>
<span class="lineNum">      26 </span><span class="lineNoCov">          0 :   added_label_.Reshape(label_shape);</span>
<span class="lineNum">      27 </span><span class="lineNoCov">          0 :   data_ = NULL;</span>
<span class="lineNum">      28 </span><span class="lineNoCov">          0 :   labels_ = NULL;</span>
<span class="lineNum">      29 </span><span class="lineNoCov">          0 :   added_data_.cpu_data();</span>
<span class="lineNum">      30 </span><span class="lineNoCov">          0 :   added_label_.cpu_data();</span>
<span class="lineNum">      31 </span><span class="lineNoCov">          0 : }</span>
<a name="32"><span class="lineNum">      32 </span>            : </a>
<span class="lineNum">      33 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">      34 </span><span class="lineNoCov">          0 : void MemoryDataLayer&lt;Dtype&gt;::AddDatumVector(const vector&lt;Datum&gt;&amp; datum_vector) {</span>
<span class="lineNum">      35 </span><span class="lineNoCov">          0 :   CHECK(!has_new_data_) &lt;&lt;</span>
<span class="lineNum">      36 </span>            :       &quot;Can't add data until current data has been consumed.&quot;;
<span class="lineNum">      37 </span>            :   size_t num = datum_vector.size();
<span class="lineNum">      38 </span><span class="lineNoCov">          0 :   CHECK_GT(num, 0) &lt;&lt; &quot;There is no datum to add.&quot;;</span>
<span class="lineNum">      39 </span><span class="lineNoCov">          0 :   CHECK_EQ(num % batch_size_, 0) &lt;&lt;</span>
<span class="lineNum">      40 </span>            :       &quot;The added data must be a multiple of the batch size.&quot;;
<span class="lineNum">      41 </span><span class="lineNoCov">          0 :   added_data_.Reshape(num, channels_, height_, width_);</span>
<span class="lineNum">      42 </span><span class="lineNoCov">          0 :   added_label_.Reshape(num, 1, 1, 1);</span>
<span class="lineNum">      43 </span>            :   // Apply data transformations (mirror, scale, crop...)
<span class="lineNum">      44 </span><span class="lineNoCov">          0 :   this-&gt;data_transformer_-&gt;Transform(datum_vector, &amp;added_data_);</span>
<span class="lineNum">      45 </span>            :   // Copy Labels
<span class="lineNum">      46 </span><span class="lineNoCov">          0 :   Dtype* top_label = added_label_.mutable_cpu_data();</span>
<span class="lineNum">      47 </span><span class="lineNoCov">          0 :   for (int item_id = 0; item_id &lt; num; ++item_id) {</span>
<span class="lineNum">      48 </span><span class="lineNoCov">          0 :     top_label[item_id] = datum_vector[item_id].label();</span>
<span class="lineNum">      49 </span>            :   }
<span class="lineNum">      50 </span>            :   // num_images == batch_size_
<span class="lineNum">      51 </span><span class="lineNoCov">          0 :   Dtype* top_data = added_data_.mutable_cpu_data();</span>
<span class="lineNum">      52 </span><span class="lineNoCov">          0 :   Reset(top_data, top_label, num);</span>
<span class="lineNum">      53 </span><span class="lineNoCov">          0 :   has_new_data_ = true;</span>
<span class="lineNum">      54 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">      55 </span>            : 
<a name="56"><span class="lineNum">      56 </span>            : #ifdef USE_OPENCV</a>
<span class="lineNum">      57 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">      58 </span><span class="lineNoCov">          0 : void MemoryDataLayer&lt;Dtype&gt;::AddMatVector(const vector&lt;cv::Mat&gt;&amp; mat_vector,</span>
<span class="lineNum">      59 </span>            :     const vector&lt;int&gt;&amp; labels) {
<span class="lineNum">      60 </span>            :   size_t num = mat_vector.size();
<span class="lineNum">      61 </span><span class="lineNoCov">          0 :   CHECK(!has_new_data_) &lt;&lt;</span>
<span class="lineNum">      62 </span>            :       &quot;Can't add mat until current data has been consumed.&quot;;
<span class="lineNum">      63 </span><span class="lineNoCov">          0 :   CHECK_GT(num, 0) &lt;&lt; &quot;There is no mat to add&quot;;</span>
<span class="lineNum">      64 </span><span class="lineNoCov">          0 :   CHECK_EQ(num % batch_size_, 0) &lt;&lt;</span>
<span class="lineNum">      65 </span>            :       &quot;The added data must be a multiple of the batch size.&quot;;
<span class="lineNum">      66 </span><span class="lineNoCov">          0 :   added_data_.Reshape(num, channels_, height_, width_);</span>
<span class="lineNum">      67 </span><span class="lineNoCov">          0 :   added_label_.Reshape(num, 1, 1, 1);</span>
<span class="lineNum">      68 </span>            :   // Apply data transformations (mirror, scale, crop...)
<span class="lineNum">      69 </span><span class="lineNoCov">          0 :   this-&gt;data_transformer_-&gt;Transform(mat_vector, &amp;added_data_);</span>
<span class="lineNum">      70 </span>            :   // Copy Labels
<span class="lineNum">      71 </span><span class="lineNoCov">          0 :   Dtype* top_label = added_label_.mutable_cpu_data();</span>
<span class="lineNum">      72 </span><span class="lineNoCov">          0 :   for (int item_id = 0; item_id &lt; num; ++item_id) {</span>
<span class="lineNum">      73 </span><span class="lineNoCov">          0 :     top_label[item_id] = labels[item_id];</span>
<span class="lineNum">      74 </span>            :   }
<span class="lineNum">      75 </span>            :   // num_images == batch_size_
<span class="lineNum">      76 </span><span class="lineNoCov">          0 :   Dtype* top_data = added_data_.mutable_cpu_data();</span>
<span class="lineNum">      77 </span><span class="lineNoCov">          0 :   Reset(top_data, top_label, num);</span>
<span class="lineNum">      78 </span><span class="lineNoCov">          0 :   has_new_data_ = true;</span>
<span class="lineNum">      79 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">      80 </span>            : #endif  // USE_OPENCV
<a name="81"><span class="lineNum">      81 </span>            : </a>
<span class="lineNum">      82 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">      83 </span><span class="lineNoCov">          0 : void MemoryDataLayer&lt;Dtype&gt;::Reset(Dtype* data, Dtype* labels, int n) {</span>
<span class="lineNum">      84 </span><span class="lineNoCov">          0 :   CHECK(data);</span>
<span class="lineNum">      85 </span><span class="lineNoCov">          0 :   CHECK(labels);</span>
<span class="lineNum">      86 </span><span class="lineNoCov">          0 :   CHECK_EQ(n % batch_size_, 0) &lt;&lt; &quot;n must be a multiple of batch size&quot;;</span>
<span class="lineNum">      87 </span>            :   // Warn with transformation parameters since a memory array is meant to
<span class="lineNum">      88 </span>            :   // be generic and no transformations are done with Reset().
<span class="lineNum">      89 </span><span class="lineNoCov">          0 :   if (this-&gt;layer_param_.has_transform_param()) {</span>
<span class="lineNum">      90 </span><span class="lineNoCov">          0 :     LOG(WARNING) &lt;&lt; this-&gt;type() &lt;&lt; &quot; does not transform array data on Reset()&quot;;</span>
<span class="lineNum">      91 </span>            :   }
<span class="lineNum">      92 </span><span class="lineNoCov">          0 :   data_ = data;</span>
<span class="lineNum">      93 </span><span class="lineNoCov">          0 :   labels_ = labels;</span>
<span class="lineNum">      94 </span><span class="lineNoCov">          0 :   n_ = n;</span>
<span class="lineNum">      95 </span><span class="lineNoCov">          0 :   pos_ = 0;</span>
<span class="lineNum">      96 </span><span class="lineNoCov">          0 : }</span>
<a name="97"><span class="lineNum">      97 </span>            : </a>
<span class="lineNum">      98 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">      99 </span><span class="lineNoCov">          0 : void MemoryDataLayer&lt;Dtype&gt;::set_batch_size(int new_size) {</span>
<span class="lineNum">     100 </span><span class="lineNoCov">          0 :   CHECK(!has_new_data_) &lt;&lt;</span>
<span class="lineNum">     101 </span>            :       &quot;Can't change batch_size until current data has been consumed.&quot;;
<span class="lineNum">     102 </span><span class="lineNoCov">          0 :   batch_size_ = new_size;</span>
<span class="lineNum">     103 </span><span class="lineNoCov">          0 :   added_data_.Reshape(batch_size_, channels_, height_, width_);</span>
<span class="lineNum">     104 </span><span class="lineNoCov">          0 :   added_label_.Reshape(batch_size_, 1, 1, 1);</span>
<span class="lineNum">     105 </span><span class="lineNoCov">          0 : }</span>
<a name="106"><span class="lineNum">     106 </span>            : </a>
<span class="lineNum">     107 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">     108 </span><span class="lineNoCov">          0 : void MemoryDataLayer&lt;Dtype&gt;::Forward_cpu(const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; bottom,</span>
<span class="lineNum">     109 </span>            :       const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; top) {
<span class="lineNum">     110 </span><span class="lineNoCov">          0 :   CHECK(data_) &lt;&lt; &quot;MemoryDataLayer needs to be initialized by calling Reset&quot;;</span>
<span class="lineNum">     111 </span><span class="lineNoCov">          0 :   top[0]-&gt;Reshape(batch_size_, channels_, height_, width_);</span>
<span class="lineNum">     112 </span><span class="lineNoCov">          0 :   top[1]-&gt;Reshape(batch_size_, 1, 1, 1);</span>
<span class="lineNum">     113 </span><span class="lineNoCov">          0 :   top[0]-&gt;set_cpu_data(data_ + pos_ * size_);</span>
<span class="lineNum">     114 </span><span class="lineNoCov">          0 :   top[1]-&gt;set_cpu_data(labels_ + pos_);</span>
<span class="lineNum">     115 </span><span class="lineNoCov">          0 :   pos_ = (pos_ + batch_size_) % n_;</span>
<span class="lineNum">     116 </span><span class="lineNoCov">          0 :   if (pos_ == 0)</span>
<span class="lineNum">     117 </span><span class="lineNoCov">          0 :     has_new_data_ = false;</span>
<span class="lineNum">     118 </span><span class="lineNoCov">          0 : }</span>
<a name="119"><span class="lineNum">     119 </span>            : </a>
<span class="lineNum">     120 </span>            : INSTANTIATE_CLASS(MemoryDataLayer);
<a name="121"><span class="lineNum">     121 </span><span class="lineCov">          3 : REGISTER_LAYER_CLASS(MemoryData);</span></a>
<span class="lineNum">     122 </span>            : 
<span class="lineNum">     123 </span><span class="lineCov">          3 : }  // namespace caffe</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
